﻿@namespace DevExpress.Blazor.AnchorUtils
@using Microsoft.AspNetCore.Components.Routing

@inject NavigationManager NavigationManager

<NavLink @attributes="@Attributes" href="@GetHref()">@ChildContent</NavLink>

@code {
    [Parameter(CaptureUnmatchedValues = true)] public Dictionary<string, object> Attributes { get; set; }

    [Parameter] public RenderFragment ChildContent { get; set; }

    string GetHref()
    {
        var hrefValue = Attributes["href"].ToString();
        if (hrefValue.StartsWith("#"))
        {
            hrefValue = NavigationManager.ToAbsoluteUri(NavigationManager.Uri).GetLeftPart(UriPartial.Path) + hrefValue;
        }
        return hrefValue;
    }
}
